﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Weka
{
    internal abstract class FieldDeserialiserProvider<T>
    {
        public abstract FieldDeserialiser<T> CreateFieldDeserialiser();
    }
    internal abstract class FieldDeserialiserProvider<T, T2> : FieldDeserialiserProvider<T>
    {
        public Action<T, T2> Writer { get; set; }
    }

    internal abstract class FieldDeserialiser<T>
    {
        public abstract void ReadWriteValue(T value, StreamReada streamReader);

        protected byte Header { get; set; }
        public virtual void ReadHeader(StreamReada streamReader)
        {
            Header = streamReader.HeaderReadBits2();
        }
    }
    internal abstract class FieldDeserialiser<T, T2> : FieldDeserialiser<T>
    {
        public Action<T, T2> Writer { get; set; }
    }


    internal class FieldDeserialiserProviderGen<T, TFD, TDT> : FieldDeserialiserProvider<T, TDT>
        where TFD : FieldDeserialiser<T, TDT>, new()
        where TDT : struct
    {
        public override FieldDeserialiser<T> CreateFieldDeserialiser() { return new TFD { Writer = Writer }; }
    }

    internal class FieldDeserialiserProviderGenN<T, TFD, TDT> : FieldDeserialiserProvider<T, TDT?>
        where TFD : FieldDeserialiser<T, Nullable<TDT>>, new()
        where TDT : struct
    {
        public override FieldDeserialiser<T> CreateFieldDeserialiser() { return new TFD { Writer = Writer }; }
    }

}
